package com.doumuxie.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author doumuxie https://gitee.com/doumuxie/
 * @version 1.0
 * @date 2020/10/12 22:00
 * @description 统一返回util
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultUtil {

    private Boolean success;

    private String msg;

    private Object data;

    private int code;

    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setSuccess(true);
        resultUtil.setCode(0);
        return resultUtil;
    }

    public static ResultUtil success(Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setSuccess(true);
        resultUtil.setData(data);
        resultUtil.setCode(0);
        return resultUtil;
    }

    public static ResultUtil error(String msg) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setSuccess(false);
        resultUtil.setMsg(msg);
        resultUtil.setCode(-1);
        return resultUtil;
    }

    public static ResultUtil error404() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setSuccess(false);
        resultUtil.setCode(404);
        return resultUtil;
    }

    public static ResultUtil paramError() {
        return error(SysCode.PARAM_ERROR);
    }

    public static ResultUtil serverBusy() {
        return error(SysCode.SERVER_BUSY);
    }

    public static ResultUtil noDataError() {
        return error(SysCode.NO_DATA);
    }

}
